package cn.cs.controller;

import cn.cs.client.AgentClient;
import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.common.EmptyUtils;
import cn.cs.pojo.Agent;
import cn.cs.pojo.CsParts;
import cn.cs.service.AgentSettlementService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/agentSettlement")
public class AgentSettlementController {

    @Resource
    private AgentSettlementService agentSettlementService;

    @Resource
    private AgentClient agentClient;


    /**
     * 分页查询 经销商商城收益 结算申请 / 历史查看
     * @param pageNumber
     * @param pageSize
     * @param state 申请状态0 申请中 1已完成(历史)
     * @param name
     * @param phone
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/csPlatform/getAgentSettlementByPage")
    public Dto getAgentSettlementByPage(Integer pageNumber, Integer pageSize, String state, String name, String person, String phone) throws Exception {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("state", state);
        param.put("name", name);
        param.put("person", person);
        param.put("phone", phone);
        if(EmptyUtils.isNotEmpty(name) || EmptyUtils.isNotEmpty(person) || EmptyUtils.isNotEmpty(phone)){
            List<Agent> list = agentClient.getAgentByNamePhone(name, person, phone);
            if(EmptyUtils.isEmpty(list) || list.size() <= 0){
                Agent agent = new Agent();
                agent.setId("000");
                list.add(agent);
            }
            param.put("list", list);
        }
        return DtoUtil.returnSuccess("获取成功", agentSettlementService.queryAgentSettlementPageByMap(param, pageNumber, pageSize));
    }


}
